package com.nondo.dean.dealer.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.nondo.dean.common.web.View;
import com.nondo.dean.dealer.model.MessageBean;

/**
 * 消息管理业务类
 * 
 * @author zhaoljin
 * @date 2018年5月10日
 */
@Component
public class MessageService {

    @Autowired
    RestTemplate restTemplate;

    /**
     * 查询用户系统消息
     * @param userId 
     * 
     * @return 信息列表List<{@link MessageBean}>
     */
    @SuppressWarnings("unchecked")
    public List<MessageBean> getMessageList(Integer userId) {
        List<MessageBean> messageList = new ArrayList<MessageBean>();
        View<LinkedHashMap<String, Object>> result =
            restTemplate.postForEntity("http://dean-push/push/v1/inner/message/list/" + userId, null, View.class)
                .getBody();
        if (result.getCode() == 20000 && result.getData() != null) {
            messageList = (List<MessageBean>)result.getData();
        }
        return messageList;
    }
}
